<?php

namespace app\mobile\model;

use think\Model;
use think\Db;
use think\Session;

class Model_index extends Model
{
//    首页使用  并且通过session 获取用户的所有信息
    public function do_session()
    {
        if (!Session::get('user')) {
            $ses = [];
            $ses['vip'] = 3;
            return $ses;
        }else{
            $ses = Db::table('mh_in_user')->where(['id'=>Session::get('user')['id']])->find();
            return $ses;
        }
    }

//    通过session 获取用户信息
    public function get_session()
    {
        $ses = Db::table('mh_in_user')->where(['id'=>Session::get('user')['id']])->find();
        return $ses;

    }

//    友情链接
    public function link()
    {
        $link = Db::table('mh_ad_link')->select();
        return $link;
    }

//    书架 的作品信息
    public function book_data($id)
    {
        $book_data = Db::field('zp.id,zp.pic,zp.name,zp.detail,zp.mark,zp.author')
            ->table(['mh_user_book'=>'ub','mh_zuopin'=>'zp'])
            ->where('ub.book_id = zp.id')
            ->where(['user_id'=>$id])
            ->select();

        return $book_data;
    }

//    会员充值成功 并刷新session
    public function vip_success($id)
    {
        $rel = Db::table('mh_in_user')->where(['id'=>$id])->update(['vip'=>2]);
        $res = Db::table('mh_in_user')->where(['id'=>$id])->find();
        Session::set('user',$res);
        $ses = Session::get('user');
    }

//    查询 用户作家表
    public function writer_user($id)
    {
        $aaa = Db::table('mh_writer_user')->where(['user_id'=>$id])->find();
        return $aaa;
    }

//    查询 用户作家申请表
    public function writer_apply($id)
    {
        $bbb = Db::table('mh_writer_apply')->where(['user_id'=>$id])->find();
        return $bbb;
    }

//    在用户申请表添加数据
    public function do_writer_apply($user_id,$user_name)
    {
        $res = Db::table('mh_writer_apply')->insert(['user_id'=>$user_id,'user_name'=>$user_name]);
        return $res;
    }



}
